package com.zhaopin.mianshi;

import java.util.Objects;

/**
 * @author yin.peide
 * @date 2021-05-10 11:29
 * 股票交易
 */
public class Sharedealin {


    public static void main(String[] args) {

        int[] attr = {2,4,1};
        System.out.println(maxProfit(attr));

    }

    public static int maxProfit(int[] prices) {
        if (Objects.isNull(prices) || prices.length == 0) {
            return 0;
        }
        int max = 0;
        int min = prices[0];

        for (int i = 0; i < prices.length; i++) {
            min = Math.min(min, prices[i]);
            max = Math.max(max, prices[i] - min);
        }

        return max;
    }


}
